package com.zhuangwei.dao;

import com.zhuangwei.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * 注意，这里不是调用mapper查数据库，
 * 而是通过RestTemplate远程查询user-service-demo中的接口
 *
 * @author LeviCoder
 * @create 2019-03-09 23:13
 */
@Component
public class UserDao {
    @Autowired
    private RestTemplate restTemplate;

    public User queryUserById(Long id){
        String url = "http://localhost:8081/user/" + id;
        return this.restTemplate.getForObject(url, User.class);
    }
}
